package thread;

public class Demo04 {
    public static void main(String[] args) {
        //匿名对象作为参数创建线程对象
        //实现 Runnable, 重写 run, 使用匿名内部类
        Thread t = new Thread(new Runnable() {
            //线程执行任务
            @Override
            public void run() {
                while(true){
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "我的线程");
        //启动线程
        t.start();

        //t.run();  //调用线程对象的run()方法

        //主线程执行的任务
        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
